package com.atguigu.educms.service.impl;

import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.mapper.CrmBannerMapper;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * Banner服务实现类
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Override
    public Page<CrmBanner> pageBanner(Long page, Long limit) {
        Page<CrmBanner> pageBanner = new Page<>(page, limit);
        
        // 构建查询条件，按照sort字段升序排序
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("sort");
        
        // 分页查询
        baseMapper.selectPage(pageBanner, wrapper);
        
        return pageBanner;
    }

    @Override
    public void addBanner(CrmBanner banner) {
        baseMapper.insert(banner);
    }

    @Override
    public CrmBanner getBannerById(String id) {
        return baseMapper.selectById(id);
    }

    @Override
    public void updateBanner(CrmBanner banner) {
        baseMapper.updateById(banner);
    }

    @Override
    public void deleteBannerById(String id) {
        baseMapper.deleteById(id);
    }
} 